<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Account/classes/PhpFox_ComponentLogin.class.php, $Author:  $ */



/** User info/actibity block
 *
 * Parameters:
 *  1. user_type    - user type to login (admin, member etc.)
 *  2. url_success  - url to forward after successfull login
 *
 * @package module.account
 * @version $Id: PhpFox_ComponentLogin.class.php 404 2008-03-17 20:03:32Z phpfoxsv $
 *
 */
class PhpFox_Mod_Account_ComponentLogin extends BaseComponent
{

    /** Processing method
     */
    function process()
    {
        $oReq = &App::getRequest();
        /* @var $oReq Request */
        
        $bDisplayCancel = $this->getParam('bDisplayCancel');

        //main processing
        switch($oReq->getAction())
        {
            case 'login':

                $oSecurity = $this->_oModule->getService('Security');
                /* @var $oSecurity PhpFox_Mod_Account_ServiceSecurity */

                $sUserType = isset($this->_aParams['user_type'])?$this->_aParams['user_type']:'';
                if ($oSecurity->login($oReq->get('login'), $oReq->get('pass'), $sUserType, $oReq->get('remember_me')))
                {                	
	               	if ( isset($_SESSION['redirect_url']) 
                		&& $_SESSION['redirect_url'] != 'public.under-construction' 
                	)
                	{
                		$sRedirectUrl = strip_tags($_SESSION['redirect_url']);
                		unset($_SESSION['redirect_url']);
                		App::gotoUrl($sRedirectUrl);
                	}
                	else
                	{
                    	if (isset($_SESSION['redirect_profile_url']))
                    	{
                    		App::gotoUrl('public.user', array('name' => $_SESSION['redirect_profile_url']));	
                    	}
                    	else 
                    	{
                    		App::gotoUrl($this->getParam('url_success', 'public.account'));
                    	}
                    }
                }
                else
                {
                    App::gotoUrl($this->getParam('url_error', ''), array(), $oSecurity->getErrors(), 'error', 'LoginForm');
                }
                break;
        }

        $oTpl = $this->_oModule->getTemplate();
        $oTpl->assign(array
        (
        	'aParams' => $this->_aParams,
        	'sRedirectUrl' => (isset($_SESSION['redirect_url']) ? $_SESSION['redirect_url'] : 'public.account'),
        	'bDisplayCancel' => $bDisplayCancel
        ));

        $sHtml = $oTpl->fetch('Login.html');
        return $sHtml;
    }

}

?>